#pragma once

#include <linux/major.h>

#define NR_REQUEST 64

struct request {
    int dev; /* -1 if no request */
    int cmd; /* READ or WRITE */
    unsigned long sector;
    unsigned long nr_sectors;
    char *buffer;
    struct buffer_head *bh;
    struct request *next;
};

#define IN_ORDER(s1, s2) \
    ((s1)->cmd < (s2)->cmd || ((s1)->cmd == (s2)->cmd && \
                               ((s1)->dev < (s2)->dev || (((s1)->dev == (s2)->dev && \
                                                           (s1)->sector < (s2)->sector)))))

struct blk_dev_struct {
    void (*request_fn)(void);
    struct request *current_request;
};

extern struct blk_dev_struct blk_dev[MAX_BLKDEV];

extern int *blksize_size[MAX_BLKDEV];

extern void hd_init();

#ifdef MAJOR_NR

#if (MAJOR_NR == HD_MAJOR)
#define DEVICE_NAME "harddisk"
#define DEVICE_INTR do_hd
#endif

#ifndef REQUEST
#define REQUEST (blk_dev[MAJOR_NR].current_request)
#endif

#ifdef DEVICE_INTR
void (*DEVICE_INTR)(void) = NULL;
#endif

#endif
